package com.property.manage.service.schedule;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.dao.schedule.ScheduleMapper;
import com.property.manage.model.schedule.ScheduleEntity;
import com.property.manage.model.schedule.ScheduleVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Component
@Slf4j
public class ScheduleService {
    @Autowired
    private ScheduleMapper scheduleMapper;


    public ScheduleEntity findSchedule(Integer id) {
        return scheduleMapper.selectById(id);
    }

    public CustomPage<ScheduleVo> schedulePage(Long pageNo, Long pageSize, Integer type,
                                               String datyDate, Integer quarterId) {
        Page<ScheduleVo> page = new Page<>(pageNo, pageSize);
        IPage<ScheduleVo> village = scheduleMapper.getScheduleEntity(page,quarterId,datyDate,type);
        return new CustomPage<>(village);
    }


    public void add(Integer frequency,String personnel,String address, Integer type, String dutyDate, Integer buildingId,String phone) {
        ScheduleEntity scheduleEntity = new ScheduleEntity();
        scheduleEntity.setAddress(address);
        scheduleEntity.setVillageId(buildingId);
        scheduleEntity.setDutyDate(dutyDate);
        scheduleEntity.setFrequency(frequency);
        scheduleEntity.setPersonnel(personnel);
        scheduleEntity.setType(type);
        scheduleEntity.setPhone(phone);
        scheduleMapper.insert(scheduleEntity);
    }

    public void update(Integer id,Integer frequency,String personnel,String address, Integer type, String dutyDate, Integer buildingId,String phone) {
        UpdateWrapper<ScheduleEntity> wrapper = new UpdateWrapper<>();
        wrapper.set("village_id", buildingId);
        wrapper.set("type", type);
        wrapper.set("frequency", frequency);
        wrapper.set("personnel", personnel);
        wrapper.set("address",address);
        wrapper.set("duty_date",dutyDate);
        wrapper.set("phone",phone);
        wrapper.eq("id",id);
        scheduleMapper.update(null,wrapper);
    }

    public void delete(Integer id) {
        scheduleMapper.deleteById(id);
    }


}
